<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
	
	<%@ include file="../layout/header.jsp" %>
    
	<!-- 主体部分开始 -->
	<div class="container" style="margin-top:10px;">
		<div class="row">
			<h1>用户管理</h1>
			<div style="margin:10px auto;">
				<a type="button" class="btn btn-primary" href="${ctx}/user.do?type=toAdd">新增</a>
				<a type="button" class="btn btn-danger" id="btnDeleteByIds" href="#" onclick="return deleteByIds();">删除</a>
			</div>
			<table class="table table-hover table-bordered">
				<tr>
					<th>
						<input type="checkbox" id="selectAll"/>
					</th>
					<th>用户编号</th>
					<th>登录名称</th>
					<th>真实姓名</th>
					<th>性别</th>
					<th>邮箱</th>
					<th>电话</th>
					<th>角色描述</th>			
					<th>操作</th>
				</tr>
				<c:forEach var="obj" items="${users}">
					<tr>					
						<td>
							<c:if test="${obj.role.description ne '系统管理员'}">
								<input type="checkbox" name="selectOne" value="${obj.id}" />
							</c:if>
						</td>
						<td>${obj.id}</td>
						<td>${obj.loginName}</td>
						<td>${obj.realName}</td>
						<td>${obj.gender eq 0?'女':'男'}</td>
						<td>${obj.email}</td>
						<td>${obj.phone}</td>	
						<td>${obj.role.description}</td>					
						<td>
							<c:if test="${obj.role.description ne '系统管理员'}">
								<a class="btn btn-warning btn-sm" href="${ctx}/user.do?type=get&id=${obj.id}">编辑</a>
								<a class="btn btn-danger btn-sm" onclick="return confirm('确定要删除【用户id】为【${obj.id}】的记录');" href="${ctx}/user.do?type=delete&id=${obj.id}">删除</a>
								<a class="btn btn-success btn-sm" onclick="return confirm('确定要重置【用户id】为【${obj.id}】的密码');" href="${ctx}/user.do?type=reset&id=${obj.id}">重置密码</a>
							</c:if>						
						</td>
					</tr>
				</c:forEach>
			</table>
		</div>
	</div>
	<!-- 主体部分结束 -->
	
    <%@ include file="../layout/footer.jsp" %>
    
    <script type="text/javascript">
    
	    function deleteByIds(){
			var id_array = new Array();
			$("input[name=selectOne]:checked").each(function(){
				id_array.push($(this).val());
			})
			var ids = id_array.join(",");
			if(ids != "" && ids.length > 0 ){
				if(confirm("是否删除选中记录？")){
					var href = "${ctx}/user.do?type=deleteByIds&ids=" + ids;    		
	        		//修改链接href属性
	        		$("#btnDeleteByIds").attr("href",href); 
	        		return true;
				}else{
					return false;
				}
			}else{
				alert("请至少选择一条记录！");
				return false;
			}    		
		}
	    
    	$(function(){
    		$("#selectAll").click(function(){
    			$("input[name=selectOne]").each(function(){
    				$(this).prop("checked",!$(this).prop("checked"));
    			})
    		});
    	})
    </script>